package com.carleasoft.mps.adu.business.position.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.adu.business.position.bean.po.AuthorityPositionPo;
import com.carleasoft.mps.adu.business.position.bean.vo.PositionVo;
import com.carleasoft.mps.adu.business.position.service.AuthorityPositionService;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.user.ThreadUserContext;
import com.carleasoft.mps.core.utils.IBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>Description: position controller</p>
 * @since 2020-05-12
 * @author ztm
 */
@RestController
@RequestMapping("/position")
public class AuthorityPositionController {
    @Autowired
    AuthorityPositionService authorityPositionService;


    /**
     * 添加岗位管理
     *
     * @param authorityPositionPo
     * @return
     */
    @PostMapping("/save")
    public R save(@RequestBody AuthorityPositionPo authorityPositionPo) {
        IBeanUtil.paramVerify(authorityPositionPo, "positionName", "positionGroupCode");
        Boolean isOk = authorityPositionService.addPosition(authorityPositionPo);
        return R.ok(isOk);
    }

    /**
     * 幂等检测岗位名称
     * @param authorityPositionPo
     * @return
     */
    @PostMapping("/checkPosition")
    public R checkPosition(@RequestBody AuthorityPositionPo authorityPositionPo){
        IBeanUtil.paramVerify(authorityPositionPo, "positionName");
        Boolean isOk=authorityPositionService.checkPosition(authorityPositionPo);
        return R.ok(isOk);
    }

    /**
     * 修改岗位管理
     *
     * @param authorityPositionPo
     * @return
     */
    @PostMapping("/update")
    public R update(@RequestBody AuthorityPositionPo authorityPositionPo) {
        Boolean isOk = authorityPositionService.updatePosition(authorityPositionPo);
        return R.ok(isOk);
    }

    /**
     * 分页查询岗位管理
     *
     * @param
     * @param authorityPositionPo
     * @return
     */
    @PostMapping("/select")
    public R select(@RequestBody AuthorityPositionPo authorityPositionPo) {
        Page page = authorityPositionService.selectList(new Page(authorityPositionPo.getCurrent(), authorityPositionPo.getSize()), authorityPositionPo);
        return R.ok(page);
    }

    /**
     * 查询岗位列表
     * @return
     */
    @PostMapping("/selectList")
    public R selectList(){
     List<PositionVo>positionVos= authorityPositionService.listPosition();
     return R.ok(positionVos);
    }


    /**
     * 根据id查询岗位管理详情
     *
     * @param authorityPositionPo
     * @return
     */
    @PostMapping("/selectById")
    public R selectById(@RequestBody AuthorityPositionPo authorityPositionPo) {
        return R.ok(authorityPositionService.findByCode(authorityPositionPo));

    }

    /**
     * 根据id删除岗位管理
     *
     * @param authorityPositionPo
     * @return
     */
    @PostMapping("/delete")
    public R delete(@RequestBody AuthorityPositionPo authorityPositionPo) {
        return R.ok(authorityPositionService.deleteById(authorityPositionPo.getPositionCode()));
    }

}
